package demo1;

class Base {
    public int a = 100;
    public int b = 200;

    public void test() {
        System.out.println("Base :: test()方法执行了...");
    }
}

class Derived extends Base {
    public int a = 101;//当出现同名的成员变量时，子类优先访问
    public int c = 201;

    public void test() {
        System.out.println("Derived :: test()方法执行了...");//父类与子类方法同名也是优先调用子类
    }

    public void method() {
//        System.out.println(a + " " + b + " " + c);
//        System.out.println(super.a);//只能访问父类的成员变量
//        System.out.println(this.a);//既能访问父类又能访问子类，优先访问子类
        System.out.println("Derived :: method()方法执行了...");
    }

    public void method2() {
        this.test();
        super.test();//只能访问父类的成员方法
        method();
    }
}

public class Test1 {
    public static void main(String[] args) {
        Derived derived = new Derived();
        derived.method2();
        //System.out.println(derived.a);
    }
}
